<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dubbo服务框架搭建指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
        }
        .code-block {
            background-color: #282c34;
            color: #abb2bf;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .code-block pre {
            margin: 0;
            padding: 1.25rem;
            font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
            font-size: 0.9rem;
            line-height: 1.5;
        }
        .code-block .comment {
            color: #5c6370;
            font-style: italic;
        }
        .code-block .keyword {
            color: #c678dd;
        }
        .code-block .string {
            color: #98c379;
        }
        .code-block .class {
            color: #e5c07b;
        }
        .code-block .method {
            color: #61afef;
        }
        .code-block .annotation {
            color: #d19a66;
        }
        .card {
            transition: all 0.3s ease;
            border-radius: 12px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <header class="relative bg-gradient-to-r from-blue-600 to-indigo-800 text-white py-20 overflow-hidden">
        <div class="container mx-auto px-6 relative z-10">
            <div class="max-w-3xl mx-auto text-center">
                <h1 class="text-4xl md:text-5xl font-bold mb-6">Dubbo分布式服务框架</h1>
                <p class="text-xl md:text-2xl font-light mb-8 leading-relaxed">构建高性能、高可用的微服务架构</p>
                <div class="flex justify-center space-x-4">
                    <a href="#getting-started" class="bg-white text-blue-700 hover:bg-blue-50 px-6 py-3 rounded-full font-semibold transition duration-300 shadow-md">
                        <i class="fas fa-rocket mr-2"></i>快速开始
                    </a>
                    <a href="#architecture" class="border-2 border-white text-white hover:bg-white hover:text-blue-700 px-6 py-3 rounded-full font-semibold transition duration-300">
                        <i class="fas fa-project-diagram mr-2"></i>架构解析
                    </a>
                </div>
            </div>
        </div>
        <div class="absolute inset-0 opacity-10">
            <div class="absolute top-0 right-0 w-64 h-64 bg-blue-300 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob"></div>
            <div class="absolute top-0 left-0 w-64 h-64 bg-indigo-300 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob animation-delay-2000"></div>
            <div class="absolute bottom-0 right-0 w-64 h-64 bg-purple-300 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob animation-delay-4000"></div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Architecture Overview -->
        <section id="architecture" class="mb-20">
            <div class="text-center mb-12">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">Dubbo架构概览</h2>
                <p class="text-lg text-gray-600 max-w-3xl mx-auto">Dubbo是一个高性能、轻量级的开源Java RPC框架，提供了三大核心能力：面向接口的远程方法调用、智能容错和负载均衡、服务自动注册与发现。</p>
            </div>
            
            <div class="grid md:grid-cols-3 gap-8 mb-12">
                <div class="card bg-white p-6">
                    <div class="text-blue-600 text-3xl mb-4">
                        <i class="fas fa-plug"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">服务提供者</h3>
                    <p class="text-gray-600">暴露服务接口实现，注册服务地址到注册中心</p>
                </div>
                <div class="card bg-white p-6">
                    <div class="text-indigo-600 text-3xl mb-4">
                        <i class="fas fa-server"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">服务消费者</h3>
                    <p class="text-gray-600">订阅所需服务，通过代理调用远程服务</p>
                </div>
                <div class="card bg-white p-6">
                    <div class="text-purple-600 text-3xl mb-4">
                        <i class="fas fa-database"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">注册中心</h3>
                    <p class="text-gray-600">负责服务注册与发现，推荐使用Zookeeper</p>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-lg p-6">
                <div class="mermaid">
                    graph LR
                    A[Consumer] -->|调用| B(Registry)
                    B -->|返回提供者列表| A
                    A -->|远程调用| C[Provider]
                    C -->|注册服务| B
                </div>
            </div>
        </section>

        <!-- Getting Started -->
        <section id="getting-started" class="mb-20">
            <div class="text-center mb-12">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">快速开始</h2>
                <p class="text-lg text-gray-600 max-w-3xl mx-auto">通过以下步骤快速搭建一个Dubbo分布式服务</p>
            </div>

            <!-- Step 1 -->
            <div class="mb-16">
                <div class="flex items-center mb-6">
                    <div class="bg-blue-600 text-white rounded-full w-10 h-10 flex items-center justify-center mr-4 text-xl font-bold">1</div>
                    <h3 class="text-2xl font-semibold text-gray-800">创建Maven工程</h3>
                </div>
                <p class="text-gray-600 mb-6">首先创建一个父工程，类型为pom，然后创建三个子模块：</p>
                <div class="grid md:grid-cols-3 gap-4 mb-6">
                    <div class="bg-blue-50 border border-blue-100 rounded-lg p-4">
                        <h4 class="font-semibold text-blue-700 mb-2"><i class="fas fa-cube mr-2"></i>dubbo-interface</h4>
                        <p class="text-gray-700">定义服务接口</p>
                    </div>
                    <div class="bg-indigo-50 border border-indigo-100 rounded-lg p-4">
                        <h4 class="font-semibold text-indigo-700 mb-2"><i class="fas fa-server mr-2"></i>dubbo-provider</h4>
                        <p class="text-gray-700">服务提供者实现</p>
                    </div>
                    <div class="bg-purple-50 border border-purple-100 rounded-lg p-4">
                        <h4 class="font-semibold text-purple-700 mb-2"><i class="fas fa-laptop mr-2"></i>dubbo-comsumer</h4>
                        <p class="text-gray-700">服务消费者</p>
                    </div>
                </div>
            </div>

            <!-- Step 2 -->
            <div class="mb-16">
                <div class="flex items-center mb-6">
                    <div class="bg-blue-600 text-white rounded-full w-10 h-10 flex items-center justify-center mr-4 text-xl font-bold">2</div>
                    <h3 class="text-2xl font-semibold text-gray-800">添加依赖</h3>
                </div>
                <p class="text-gray-600 mb-4">在父工程中添加Dubbo和Zookeeper客户端依赖：</p>
                <div class="code-block mb-6">
                    <pre><code>&lt;!-- 引入dubbo的依赖 --&gt;
<span class="keyword">&lt;dependency&gt;</span>
    <span class="keyword">&lt;groupId&gt;</span>com.alibaba<span class="keyword">&lt;/groupId&gt;</span>
    <span class="keyword">&lt;artifactId&gt;</span>dubbo<span class="keyword">&lt;/artifactId&gt;</span>
    <span class="keyword">&lt;version&gt;</span>2.5.8<span class="keyword">&lt;/version&gt;</span>
<span class="keyword">&lt;/dependency&gt;</span>

<span class="comment">&lt;!-- zookeeper客户端依赖 --&gt;</span>
<span class="keyword">&lt;dependency&gt;</span>
    <span class="keyword">&lt;groupId&gt;</span>com.github.sgroschupf<span class="keyword">&lt;/groupId&gt;</span>
    <span class="keyword">&lt;artifactId&gt;</span>zkclient<span class="keyword">&lt;/artifactId&gt;</span>
    <span class="keyword">&lt;version&gt;</span>0.1<span class="keyword">&lt;/version&gt;</span>
<span class="keyword">&lt;/dependency&gt;</span></code></pre>
                </div>
            </div>

            <!-- Step 3 -->
            <div class="mb-16">
                <div class="flex items-center mb-6">
                    <div class="bg-blue-600 text-white rounded-full w-10 h-10 flex items-center justify-center mr-4 text-xl font-bold">3</div>
                    <h3 class="text-2xl font-semibold text-gray-800">服务提供者</h3>
                </div>
                
                <div class="mb-8">
                    <h4 class="text-xl font-semibold text-gray-700 mb-4 flex items-center">
                        <i class="fas fa-code mr-2 text-blue-500"></i>服务实现类
                    </h4>
                    <div class="code-block">
                        <pre><code><span class="annotation">@Service</span>
<span class="keyword">public class</span> <span class="class">UserServiceImpl</span> <span class="keyword">implements</span> <span class="class">IUserService</span> {
    <span class="annotation">@Override</span>
    <span class="keyword">public</span> String <span class="method">add</span>(String username) {
        System.out.println("username = [" + username + "]");
        <span class="keyword">return</span> "return :"+username;
    }
}</code></pre>
                    </div>
                </div>

                <div class="mb-8">
                    <h4 class="text-xl font-semibold text-gray-700 mb-4 flex items-center">
                        <i class="fas fa-cog mr-2 text-blue-500"></i>配置
                    </h4>
                    <div class="code-block">
                        <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<span class="keyword">&lt;beans</span> xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://code.alibabatech.com/schema/dubbo
       http://code.alibabatech.com/schema/dubbo/dubbo.xsd"&gt;

    <span class="comment">&lt;!-- 服务名称 --&gt;</span>
    <span class="keyword">&lt;dubbo:application</span> name="user_service"<span class="keyword">/&gt;</span>

    <span class="comment">&lt;!-- 注册中心地址 --&gt;</span>
    <span class="keyword">&lt;dubbo:registry</span> address="zookeeper://192.168.193.110:2181"<span class="keyword">/&gt;</span>

    <span class="comment">&lt;!-- 端口号 --&gt;</span>
    <span class="keyword">&lt;dubbo:protocol</span> port="-1"<span class="keyword">/&gt;</span>

    <span class="comment">&lt;!-- 注解 --&gt;</span>
    <span class="keyword">&lt;dubbo:annotation</span> package="com.qf.service"<span class="keyword">/&gt;</span>
<span class="keyword">&lt;/beans&gt;</span></code></pre>
                    </div>
                </div>

                <div class="mb-8">
                    <h4 class="text-xl font-semibold text-gray-700 mb-4 flex items-center">
                        <i class="fas fa-paper-plane mr-2 text-blue-500"></i>发布服务
                    </h4>
                    <div class="code-block">
                        <pre><code><span class="keyword">public class</span> <span class="class">Test</span> {
    <span class="keyword">public static void</span> <span class="method">main</span>(String[] args) <span class="keyword">throws</span> Exception {
        <span class="comment">// 初始化Spring容器</span>
        ApplicationContext ctx = <span class="keyword">new</span> ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        <span class="comment">// 按任意键退出</span>
        System.in.read();
    }
}</code></pre>
                    </div>
                </div>
            </div>

            <!-- Step 4 -->
            <div class="mb-16">
                <div class="flex items-center mb-6">
                    <div class="bg-blue-600 text-white rounded-full w-10 h-10 flex items-center justify-center mr-4 text-xl font-bold">4</div>
                    <h3 class="text-2xl font-semibold text-gray-800">服务调用者</h3>
                </div>
                
                <div class="mb-8">
                    <h4 class="text-xl font-semibold text-gray-700 mb-4 flex items-center">
                        <i class="fas fa-mobile-alt mr-2 text-blue-500"></i>调用服务
                    </h4>
                    <div class="code-block">
                        <pre><code><span class="annotation">@RunWith</span>(SpringJUnit4ClassRunner.class)
<span class="annotation">@ContextConfiguration</span>(value = "classpath:applicationContext.xml")
<span class="keyword">public class</span> <span class="class">ConsumerTest</span> {
    <span class="annotation">@Autowired</span>
    <span class="keyword">private</span> <span class="class">IUserService</span> userService;

    <span class="annotation">@Test</span>
    <span class="keyword">public void</span> <span class="method">testAdd</span>() <span class="keyword">throws</span> Exception {
        System.out.println(userService.add("admin"));
    }
}</code></pre>
                    </div>
                </div>

                <div class="mb-8">
                    <h4 class="text-xl font-semibold text-gray-700 mb-4 flex items-center">
                        <i class="fas fa-cog mr-2 text-blue-500"></i>配置
                    </h4>
                    <div class="code-block">
                        <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<span class="keyword">&lt;beans</span> xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://code.alibabatech.com/schema/dubbo
       http://code.alibabatech.com/schema/dubbo/dubbo.xsd"&gt;

    <span class="keyword">&lt;dubbo:application</span> name="user_web"<span class="keyword">/&gt;</span>
    <span class="keyword">&lt;dubbo:registry</span> check="false" address="zookeeper://192.168.193.110:2181"<span class="keyword">/&gt;</span>
    <span class="keyword">&lt;dubbo:consumer</span> cache="false" retries="3"<span class="keyword">/&gt;</span>

    <span class="comment">&lt;!-- 生成远程服务代理，可以跟本地bean一样使用UserService --&gt;</span>
    <span class="keyword">&lt;dubbo:reference</span> interface="com.qf.service.IUserService" id="userService"<span class="keyword">/&gt;</span>
<span class="keyword">&lt;/beans&gt;</span></code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Best Practices -->
        <section class="bg-white rounded-xl shadow-lg p-8 mb-16">
            <h2 class="text-2xl font-bold text-gray-800 mb-6 flex items-center">
                <i class="fas fa-lightbulb text-yellow-500 mr-3"></i>最佳实践建议
            </h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="flex">
                    <div class="text-blue-500 text-xl mr-4 mt-1">
                        <i class="fas fa-check-circle"></i>
                    </div>
                    <div>
                        <h3 class="font-semibold text-gray-800 mb-2">接口与实现分离</h3>
                        <p class="text-gray-600">服务接口单独放在dubbo-interface模块中，服务提供者和消费者都依赖此模块，确保接口一致性。</p>
                    </div>
                </div>
                <div class="flex">
                    <div class="text-blue-500 text-xl mr-4 mt-1">
                        <i class="fas fa-check-circle"></i>
                    </div>
                    <div>
                        <h3 class="font-semibold text-gray-800 mb-2">版本控制</h3>
                        <p class="text-gray-600">当接口变更时，使用Dubbo的版本控制功能来平滑过渡，避免影响现有服务调用。</p>
                    </div>
                </div>
                <div class="flex">
                    <div class="text-blue-500 text-xl mr-4 mt-1">
                        <i class="fas fa-check-circle"></i>
                    </div>
                    <div>
                        <h3 class="font-semibold text-gray-800 mb-2">超时设置</h3>
                        <p class="text-gray-600">根据服务特性合理设置超时时间，避免因网络问题导致线程长时间阻塞。</p>
                    </div>
                </div>
                <div class="flex">
                    <div class="text-blue-500 text-xl mr-4 mt-1">
                        <i class="fas fa-check-circle"></i>
                    </div>
                    <div>
                        <h3 class="font-semibold text-gray-800 mb-2">监控中心</h3>
                        <p class="text-gray-600">配置Dubbo监控中心，实时监控服务调用情况和性能指标。</p>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto px-6">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-semibold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">分享前沿技术，提升开发效率</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition duration-300">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>